Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mag l1a compression #801

Merged

Conversation

maxinelasp
Copy link
Contributor

Change Summary

This is a pretty involved PR. I would like to thank in advance anyone who reviews. I don't think breaking this code up further would make sense, or I would have done so.

I'd recommend starting by reading the docstring for "process_compressed_vectors" in mag_l1a_data.py, as it gives a good overview on the overall algorithm.

Note: "process_uncompressed_vectors" was moved into a new method but otherwise unchanged.

Overview

  • Added MAG decompression option
  • Added tests

Updated Files

  • mag_l1a_data.py

    • Added 7 new methods to decode compressed data
  • test_mag_l1a

    • Added tests
  • mag_l0_data

    • Minor fix for mypy

Testing

Testing is pretty extensive for this change, since it's so complex. I generated test data primarily using a piece of code that the MAG team provided for me.

Closes issue #727

@maxinelasp maxinelasp requested review from alastairtree and a team August 30, 2024 15:26
@maxinelasp maxinelasp self-assigned this Aug 30, 2024
@maxinelasp maxinelasp requested review from vmartinez-cu and laspsandoval and removed request for a team August 30, 2024 15:26
@maxinelasp
Copy link
Contributor Author

pre-commit.ci autofix

imap_processing/mag/constants.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
Copy link
Contributor

@laspsandoval laspsandoval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting concept. Only a few suggestions.

imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
@vmartinez-cu
Copy link
Contributor

Nice job with your doc strings and comments. The details are helpful

Copy link

@alastairtree alastairtree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Epic effort maxine, thank you!

I have left you lots of comments (sorry!). Lots are just style and readability stuff - i know how hard it is to make this compression logic comprehendable so I feel your pain.

Think my only other query is on error handling. I think it should be a bit more defensive and if you get any bad unexpected values it means something awful has happened and the whole packet should be considered a stream of NaNs and an error raised somewhere so we can investigate..

Thank you!

imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
# the range
uncompressed_vector_size = compression_width * 3 + 2
# plus 8 to get past the compression width and range data section
first_vector_width = uncompressed_vector_size + 8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand the +8 here - you are aready skipping 8 bits in bit array on line 546?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the index of the end of the first vector, so it's uncompressed_vector size long, but we need to skip past the first 8 bits - so the end index is uncompressed_size plus 8. I can move the +8 into the slice in line 546, if that makes more sense?

imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/tests/mag/test_mag_l1a.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Outdated Show resolved Hide resolved
imap_processing/mag/l1a/mag_l1a_data.py Show resolved Hide resolved
@maxinelasp
Copy link
Contributor Author

@alastairtree @tech3371 @sdhoyt @laspsandoval Thank you so much for your reviews! I have addressed all the comments on this PR, added some additional tests, and had the output validated by the MAG team. Could I get a re-review and maybe an approval from you?

Copy link
Contributor

@sdhoyt sdhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me. Nice work!

@alastairtree
Copy link

There are a couple of comments of mine that you "thumbs up'd" / replied to but didn't actually change, which is fine but might be worth checking you have pushed all your changes if not. Otherwise looks good!

@maxinelasp
Copy link
Contributor Author

@alastairtree Thanks for that final review! I will double check that I addressed everything, there were a few comments that I preferred to leave as-is, but I definitely want to make sure I decided on everything. If there are any comments that you definitely want to see changed, please let me know.

@maxinelasp
Copy link
Contributor Author

@alastairtree Thanks for pointing out those comments, I guess I resolved a bunch of them in some kind of fugue state on Friday afternoon and didn't actually fix the things you were pointing out! I went back in and I'm addressing your comments, including a bunch on the tests that I missed. Sorry about that, I got a little over eager to finish this up 😅

@maxinelasp maxinelasp merged commit 1effdb0 into IMAP-Science-Operations-Center:dev Sep 20, 2024
17 checks passed
@maxinelasp maxinelasp mentioned this pull request Oct 9, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants